<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="报障单号" prop="reportId">
        <el-input
          v-model="queryParams.reportId"
          placeholder="请输入报障单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="标题" prop="reportTitle">
        <el-input
          v-model="queryParams.reportTitle"
          placeholder="请输入标题"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['report:ReportOrder:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ReportOrderList">
      <el-table-column label="报障单号" align="center" prop="reportId" width="200px"/>
      <el-table-column label="故障地点" align="center" prop="reportLocation"/>
      <el-table-column label="标题" align="center" prop="reportTitle"/>
      <el-table-column label="故障大类" align="center" prop="reportTypeBigName"/>
      <el-table-column label="故障小类" align="center" prop="reportTypeSmallName"/>
      <el-table-column label="故障描述" align="center" prop="reportDesc"/>
      <el-table-column label="报障单状态" align="center" prop="reportStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.report_status" :value="scope.row.reportStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="发起人" align="center" prop="reportUserName"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="getOrder(scope.row.id)"
            v-if="scope.row.reportStatus == 'CREATE'"
          >接单
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="详情" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleDetail(scope.row)"
          >查看详情
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="历史记录" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-more"
            @click="handleHistory(scope.row)"
          >历史
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <report-time-line :history-drawer-open.sync="historyDrawerOpen" :time-line-item-list="timeLineItemList"/>
    <el-dialog :visible.sync="reportOrderDetailOpen" width="800px">
      <el-descriptions class="margin-top" title="报障单详情" :column="3" size="mini" border>
        <el-descriptions-item label="报障人">
          {{ reportOrderDetail.reportUserName }}
        </el-descriptions-item>
        <el-descriptions-item label="故障地点">
          {{ reportOrderDetail.reportLocation }}
        </el-descriptions-item>
        <el-descriptions-item>
        </el-descriptions-item>
        <el-descriptions-item label="手机号">
          {{ reportOrderDetail.phone }}
        </el-descriptions-item>
        <el-descriptions-item label="邮箱">
          {{ reportOrderDetail.email }}
        </el-descriptions-item>
        <el-descriptions-item label="qq号">
          {{ reportOrderDetail.qq }}
        </el-descriptions-item>
        <el-descriptions-item label="故障标题">
          {{ reportOrderDetail.reportTitle }}
        </el-descriptions-item>
        <el-descriptions-item label="故障大类">
          {{ reportOrderDetail.reportTypeBigName }}
        </el-descriptions-item>
        <el-descriptions-item label="故障小类">
          {{ reportOrderDetail.reportTypeSmallName }}
        </el-descriptions-item>
        <el-descriptions-item label="故障描述">
          {{ reportOrderDetail.reportDesc }}
        </el-descriptions-item>
      </el-descriptions>
      <el-descriptions style="margin-top: 10px" title="处理状态" :column="3" size="mini" border>
        <el-descriptions-item label="报障单状态">
          {{ getDicLabelByValue(this.dict.type.report_status, reportOrderDetail.reportStatus) }}
        </el-descriptions-item>
        <el-descriptions-item label="处理次数">
          {{ reportOrderDetail.reportDealCount }}
        </el-descriptions-item>
        <el-descriptions-item label="处理人">
          {{ reportOrderDetail.reportDealUserName }}
        </el-descriptions-item>
      </el-descriptions>
      <el-descriptions v-if="reportOrderDetail.reportFiles" style="margin-top: 10px" title="附件信息" :column="1"
                       size="mini" border>
        <el-descriptions-item v-for="(url,index) in reportOrderDetail.reportFiles.split(';')" :label="'附件'+index">
          <a :href="getBaseUrl(url)">下载查看</a>
        </el-descriptions-item>
      </el-descriptions>
      <div class="dialog-footer" style="margin-top: 10px;text-align: right">
        <el-button type="primary" @click="getOrderBtn">接单</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {parseTime} from "@/utils/ruoyi";
import request from "@/utils/request";
import reportTimeLine from "@/views/report/comp/reportTimeLine";

export default {
  name: "GetReportOrder",
  dicts: ['report_status'],
  components: {
    reportTimeLine
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报障单表格数据
      ReportOrderList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        reportTitle: null,
        reportUserId: null,
      },
      historyDrawerOpen: false,
      timeLineItemList: [],
      reportOrderDetail: {},
      reportOrderDetailOpen: false
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getOrderBtn(){
      this.getOrder(this.reportOrderDetail.id)
    },
    getOrder(id) {
      this.$confirm('确认接单吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true
        this.reportOrderDetailOpen = false
        request({
          url: '/report/ReportOrder/getOrder/'+id,
          method: 'post',
          params: this.queryParams
        }).then(res=>{
          this.loading = false
          this.getList()
        })
      }).catch(() => {});
    },
    getBaseUrl(url) {
      return process.env.VUE_APP_BASE_API + '/file/download?path=' + url
    },
    /** 查询报障单列表 */
    getList() {
      this.loading = true;
      request({
        url: '/report/ReportOrder/listAllCreated',
        method: 'get',
        params: this.queryParams
      }).then(response => {
        this.ReportOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 查看详情操作 */
    handleDetail(row) {
      var id = row.id
      request({
        url: '/report/ReportOrder/noAuth/' + id,
        method: 'get'
      }).then(res => {
        this.reportOrderDetail = res.data
        this.reportOrderDetailOpen = true
      })
    },
    handleHistory(row) {
      const id = row.id
      request({
        url: '/report/ReportOrder/reportHistoryNoAuth/' + id,
        method: 'get'
      }).then(res => {
        this.timeLineItemList = res.data
      })
      //查询历史，右侧显示流程
      this.historyDrawerOpen = true
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('report/ReportOrder/export', {
        ...this.queryParams
      }, `ReportOrder_${new Date().getTime()}.xlsx`)
    }
  },
  activated() {
    let refresh = this.$route.query.refresh
    if (refresh == "true") {
      this.getList()
    }
  },
};
</script>
